﻿layui.use(['form', 'layer', 'jquery', 'laypage'], function () {
    var form = layui.form,
       $ = layui.jquery,
	   layer = parent.layer === undefined ? layui.layer : parent.layer,
		laypage = layui.laypage,
		pageData = {
		    "PageSize": 5, "PageCount": 0, "PageNumber": 0, "RowCount": 0, "Where": $("input[name='address']:checked").val()
		};
    function getList(that) {
        $.ajax({
            type: "POST",
            url: "/Recruitment/select",
            data: that,
            dataType: "json",
            success: function (data) {
                var result = JSON.parse(data.Data);
                var usersData = result.DataList;
                pageData.PageCount = result.PageCount;
                pageData.PageNumber = result.PageNumber;
                pageData.PageSize = result.PageSize;
                pageData.RowCount = result.RowCount;
                //执行加载数据的方法
                renderDate(usersData);
                showPage(pageData);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.alert(textStatus);
            }
        });
        //渲染数据
        function renderDate(list) {
            var dataHtml = '';
            if (list != null) {
                layui.each(list, function (index, item) {
                    var plantype = "";
                    dataHtml += '<tr>'
                    + '<td>' + item.PlanID + '</td>'
                    + '<td>' + item.PlanAmount + '</td>'
                    + '<td>' + item.Salary + '</td>'
                    + '<td>' + (item.PlanState == 0 ? "已发布" : "未发布") + '</td>'
                    + '<td>' + item.PostName + '</td>'
                     + '<td>' + item.PlanPeriod + '</td>'
                    + '</tr>';
                });
            } else {
                dataHtml = '<tr><td colspan="8">暂无数据</td></tr>';
            }
            $(".news_content").html(dataHtml);   //渲染数据
            $('.news_list thead input[type="checkbox"]').prop("checked", false);
            form.render(); //渲染表单
        }

    }
    //分页
    function showPage(page) {
        laypage({
            cont: 'page',
            pages: page.PageCount,//得到总页数
            curr: page.PageNumber + 1,
            groups: 5, //连续显示分页数
            jump: function (obj, first) {
                if (!first) {//防止无限刷新
                    page.PageNumber = obj.curr - 1;
                    getList(page);
                }
            }
        });
    }

    form.on('submit(QueryForm)', function () {
        pageData.Where = $("input[name='address']:checked").val();
        getList(pageData);
        return false;
    });
    $(function () {
        getList(pageData);
    });
})